import { acceptHMRUpdate, defineStore } from 'pinia'
import { useMenuNavApi, useMenuAllApi } from '@/api/menu'
import { generateRoutes } from '@/router'
import { RouteRecordRaw } from 'vue-router'
import { developmentRouter } from '@/config/menu'
import { setRouterMenuList } from '@/utils/tool'
import { Storage } from '@/utils/storage'
import PageAccounts from '@/views/PageAccounts/Index.vue'

const isDevelopment = import.meta.env.MODE == 'development';

export const routerStore = defineStore('routerStore', {
	state: () => ({
		menuList: [],
		menuRoutes: [] as RouteRecordRaw[],
		searchMenu: [] as RouteRecordRaw[],
		routes: [] as RouteRecordRaw[]
	}),
	actions: {
		async getMenuRoutes() {
			const dataThen: any = []
			dataThen.push(...developmentRouter)
			// 替换图标
			// dataThen.forEach((item:any) => {
			// 	const fitem = allData.data?.find((i:any) => i.route == item.url)
			// 	if (fitem) {
			// 		item.icon = fitem.icon
			// 	}
			// });
			const routes = generateRoutes(dataThen)
			this.menuRoutes.push(...routes)

			return this.menuRoutes
		},
		setSearchMenu(routers: RouteRecordRaw[]) {
			this.searchMenu = routers
		},
		setRoutes(routers: RouteRecordRaw[]) {
			this.routes = routers
		},
	}
})
// 确保传递正确的 store 声明，本例中为 `useAuth`
if (import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(routerStore, import.meta.hot))
}
